//package com.example.demo.component.download;
//
//import jakarta.servlet.ServletException;
//import jakarta.servlet.ServletOutputStream;
//import jakarta.servlet.annotation.WebServlet;
//import jakarta.servlet.http.HttpServlet;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import lowerbound.ind.helper.api_result;
//import oraps.daedalus.helper.http_client_helper;
//import oraps.daedalus.helper.log_helper;
//import oraps.daedalus.login.login_api;
//import org.apache.logging.log4j.Logger;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.net.URLEncoder;
//import java.util.Map;
//
//@WebServlet(name = "login_servlet", value = "/login")
//public class login_servlet extends HttpServlet {
//
//    private static final Logger logger = log_helper.getLogger(login_servlet.class);
//
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String path = "C:\\Users\\BG264\\Desktop\\mysql_backup.zip";
//        String fileName = "yanceysong.zip";
//        resp.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
//        FileInputStream inputStream = new FileInputStream(new File(path));
//        int len = 0;
//        byte[] buffer = new byte[1024];
//        ServletOutputStream outputStream = resp.getOutputStream();
//        while ((len = inputStream.read(buffer)) != -1) {
//            outputStream.write(buffer, 0, len);
//        }
//        inputStream.close();
//        outputStream.close();
//    }
//
//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        PrintWriter out = resp.getWriter();
//        http_client_helper.set_header(req, resp);
//        Map<String, String> parameters = http_client_helper.get_param_in_request(req);
//        String operation = parameters.getOrDefault("operation", "");
//        String param = parameters.getOrDefault("value", "");
//        api_result result = new api_result();
//
//        switch (operation) {
//            case "LOGIN":
//                result = login_api.login(param);
//                break;
//            default:
//                result.state = 1;
//                result.error_message = "不支持的操作";
//                break;
//        }
//
//        out.write(result.to_json_string());
//        out.close();
//    }
//
//}
//
